<?php
/**
 * Created by PhpStorm.
 * User: dreamy
 * Date: 2019-06-22
 * Time: 09:31
 */
use yii\helpers\Html;
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>账本管理-<?= \common\services\DomainExtraConfigService::getVal('name');?></title>
    <meta name="keywords" content="<?= $this->params['seoData']['keywords'] ?>">
    <meta name="description" content="<?= $this->params['seoData']['description'] ?>">
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/global.css">
    <?php echo $this->render('../public/ele.php')?>
</head>
<body id="app">
<?=Html::cssFile('@web/static/css/index.css')?>
<!--引入页面头部-->
<?php echo $this->render('../public/header.php')?>
<?=Html::jsFile('@web/static/js/jquery-3.4.1.min.js')?>

<style>
    #app{
        background: #f9f9f9ee;
    }
     [v-cloak]{
         display: none
     }
    .company-name{
        font-weight: bold;
        color: rgb(51 150 250);
    }
</style>
<div id="ContainerMain" v-cloak>
    <div style="width: 1000px;margin: 100px auto;">
        <div style="height: 400px;text-align: center;margin-top: 200px;">
            <el-row type="flex" class="row-bg" justify="center">
                <el-col :span="10"><div class="grid-content bg-purple">
                        <p style="margin-bottom: 20px;">您将授权
                            <span class="company-name">
                                <?php echo $companyName;?>
                            </span>
                           查看账单流水，请确认</p>
                        <el-select placeholder="选择授权账套" filterable default-first-option v-model="authTallyId" filterable>
                            <el-option
                                    v-for="item in tallyData"
                                    :key="item.id"
                                    :label="item.title"
                                    :value="item.id">
                            </el-option>
                        </el-select>
                        <p style="margin-top: 20px;">
                            <el-button type="primary" size="medium" @click="authSubmit">确定授权</el-button>
                        </p>
                    </div>
                </el-col>
            </el-row>
        </div>
    </div>
</div>

<div style="height: 100px;"></div>
<?php echo $this->render('../public/footer.php')?>

<script type="application/javascript">
    let loginToken  =  localStorage.getItem('loginToken');
    let financeId  = '<?php echo $financeId;?>';
    let companyId  = '<?php echo $companyId;?>';
    new Vue({
        el:'#ContainerMain',
        data() {
            return {
                tallyData:[],
                authTallyId:'',
            }
        },
        computed: {},
        mounted:function() {
            if(!logined){
                location.href='/login'
            }
            this.getTallyList(1)
        },
        methods:{
            authSubmit(){
                let that = this
                if(that.authTallyId=='') {
                    that.showTips('info','请选择要授权的账套');
                    return false;
                }
                location.href = 'https://www.ygs.cn/GszApi/cwgjbind.html?companyId='+companyId+'&financeId=' + financeId+ '&gszTallyId=' + that.authTallyId
            },
            getTallyList(page){
                let that = this
                axios.get('/api/tally/lists',{
                    method: 'get',
                    headers: {'token': loginToken},
                    params: {
                        page:page || 1
                    }
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.tallyData = res.data.data
                    }else{
                        that.$emit('show_tips','error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            showTips(type,msg){
                this.$message({
                    type: type,
                    message: msg
                });
            }
        },
    })
</script>
</body>
</html>
